<?php

class playlist extends model {
	
	var $name;
		
	function getListOfNames($featured = 0) {
		return $this->sql("SELECT * FROM playlist WHERE featured = " . (int) $featured . " ORDER BY name");
	}
	
	function getListOfVideos($random = false, $limit = false) {
		$sql = "SELECT * FROM playlistcontent WHERE playlist_id = ".$this->getId();
		if ($random) {
			$sql .= " ORDER BY RAND()";
		}
		if ($limit)  {
			$sql .= " LIMIT 0, $limit";
		}
		return $this->sql($sql);
	}
	
	/**
	 * 
	 * @param $random boolean 
	 * @param $limit boolean
	 * @return video_collection
	 */
	function getContent($random = false, $limit = false) {
		$ret = array();
		$list = $this->getListOfVideos($random, $limit);
		$videos = new video_collection();
		foreach ($list as $row) {
			$videos->addItem(new video($row->video_id));
		}
		return $videos;		
	}
	
}

?>